import Taro from "@tarojs/taro"

function tianSetItem(key, data) {
    Taro.setStorageSync(key, JSON.stringify(data))
}


function tianGetItem(key) {
    if (Taro.getStorageSync(key)) {
        return JSON.parse(Taro.getStorageSync(key))
    }
}

function tianRemoveItem(key) {
    Taro.removeStorageSync(key)
}

function unique(arr, key = '') {
    let temparr = []
    let obj = {}
    arr.forEach(item => {
        obj[item[key]] ? '' : obj[item[key]] = true && temparr.push(item)
    });
    return temparr
}
function jinjie_unique(arr, key = '') {
    let temparr = []
    let obj = {}
    temparr = arr.reduce((pre, next) => {
        obj[next[key]] ? '' : obj[next[key]] = true && pre.push(next)
        return pre
    }, [])
    return temparr
}

const tools = {
    tSet: tianSetItem,
    tGet: tianGetItem,
    tRemove: tianRemoveItem
}

export default tools